<template>
	<view>
		<view class="tipflex">
			<view class="item" v-for="(item,index) in list" :key="index" :class="item.default?'itemact':''"
				@click="radioChange(item)">
				{{item.dictLabel}}
			</view>
		</view>
		<view class="footerbtn" @click="handleSave">
			<view class="cont">
				<view class="btn" >
					保存
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getdict
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				list: [],
				ulist: []
			};
		},
		onLoad(query) {
			getdict('self_shop_category').then(res=>{
				this.list = res.data
				this.list.filter(item=>{
					if(item.dictValue == query.nowtype){
						item.default = true
					}
				})
			})
		},
		methods: {
			handleSave() {
				this.ulist = this.list.filter(item=>{return item.default})
				if(this.ulist.length==0){
					uni.showToast({
						title:'请选择一个品类',
						icon:'none'
					})
				}
				uni.$emit('nowType',this.ulist[0])
				uni.navigateBack()
			},
			//单选
			radioChange(item) {
				this.list.forEach(item => {
					item.default = false
				})
				item.default = !item.default
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F5F5;
	}

	.tipflex {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		padding:40rpx;
		box-sizing: border-box;
		.item {
			width: 210rpx;
			height: 76rpx;
			background: #FFFFFF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			line-height: 76rpx;
			margin-right: 20rpx;
			margin-bottom: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #000000;
			text-align: center;
		}
		.item:nth-child(3n){
			margin-right: 0;
		}
		.itemact {
			background: #000000 !important;
			color: #FFFFFF !important;
		}
	}
	.footerbtn {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		position: fixed;
		bottom: 0%;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	
		.cont {
			display: flex;
			padding: 10rpx 20rpx;
			height: 120rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			align-items: center;
			justify-content: center;
			.btn {
				width: 670rpx;
				height: 100rpx;
				background: #000000;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				color: #FFFFFF;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 100rpx;
				text-align: center;
			}
			.absbtn{
				background: #808080;
			}
		}
	}
</style>